﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel.Composition;


namespace Kooboo.Commerce.Repositories
{
    [Export(typeof(IShopSetting))]
    public partial class ShopSetting:Entity, IShopSetting
    {

        #region IShopSetting Members

  
        IImageSettings _ImageSettings;
        public IImageSettings ImageSettings
        {
            get
            {
                if (this._ImageSettings == null)
                {

                    var sizes = this.DataContext.ImageSizes.ToList();

                    var settings = new ImageSettings();
                    settings.Thumbnail = sizes.Where(i => i.Name == "Thumnail" && i.IsCustom == false).FirstOrDefault() ?? new ImageSize() { Name = "Thumnail", Height = 100, Width = 100 };
                    settings.Detail = sizes.Where(i => i.Name == "Detail" && i.IsCustom == false).FirstOrDefault() ?? new ImageSize() { Name = "Detail", Height = 500, Width = 500 };
                    settings.Cart = sizes.Where(i => i.Name == "Cart" && i.IsCustom == false).FirstOrDefault() ?? new ImageSize() { Name = "Cart", Height = 50, Width = 50 };
                    settings.List = sizes.Where(i => i.Name == "List" && i.IsCustom == false).FirstOrDefault() ?? new ImageSize() { Name = "List", Height = 50, Width = 50 };

                    settings.CustomSizes = sizes.Where(i => i.IsCustom).Select(i => i as IImageSize).ToList();

                    this._ImageSettings = settings;

                }

                return this._ImageSettings;
            }
            set
            {
                this._ImageSettings = value;
            }
        }

        #endregion
    }

      [Export(typeof(IImageSettings))]
    public class ImageSettings : IImageSettings
    {
        public ImageSettings()
        {
            this.CustomSizes = new List<IImageSize>();
        }

        #region IImageSettings Members

        public IImageSize Thumbnail
        {
            get;
            set;
        }

        public IImageSize Detail
        {
            get;
            set;
        }

        public IImageSize List
        {
            get;
            set;
        }

        public IImageSize Cart
        {
            get;
            set;
        }

        public List<IImageSize> CustomSizes
        {
            get;
            set;
        }

        #endregion
    }
}
